<%@ page import="com.the8thfold.anton.ant.AntJobUser; com.the8thfold.anton.ant.AntScriptUser; com.the8thfold.anton.ant.AntJob; com.the8thfold.anton.ant.AntScript; com.the8thfold.anton.users.Role; org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils; com.the8thfold.anton.users.Roles; org.apache.tools.ant.Target" contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>View User</title>
    <meta name="layout" content="main" />

    <link rel="stylesheet" href="${resource(dir:'js/codemirror',file:'codemirror.css')}" />
    <link rel="stylesheet" href="${resource(dir:'js/codemirror/mode/xml',file:'xml.css')}" />

    <g:javascript library="codemirror/overlay" />
    <g:javascript library="codemirror/codemirror" />
    <g:javascript library="codemirror/mode/xml/xml" />

    <g:javascript>
        $(document).ready(function(){
        });
    </g:javascript>

</head>
<body>

<div>
    <h1>User: ${account.username}</h1>
    <hr/>
    <br/>
    <span><b>Created:</b> <prettytime:display date="${account.dateCreated}"/> </span>
    <g:if test="${error}">
        <div class="errors">${error}</div>
        <br/>
    </g:if>
    <div class="css_right toolbar">
        <sec:ifAllGranted roles="${Roles.ROLE_ADMIN}">
            <g:if test="${account.userId.equals(sec.loggedInUserInfo(field: 'userId').toString())}">
                <a class="btn-text popup-remote" href="${createLink(controller: 'account', action: 'changePasswordSelf', id: account?.userId)}">Change Password</a>
            </g:if>
            <g:else>
                <a class="btn-text popup-remote" href="${createLink(controller: 'account', action: 'changePassword', id: account?.userId)}">Change Password</a>
            </g:else>
            <g:unless test="${account.username == 'admin'}">
                <g:if test="${account.enabled}">
                    <a class="btn-text" href="${createLink(controller: 'account', action: 'disable', id: account.userId, params: [origin: request.forwardURI.toString().decodeURL()])}">Disable</a>
                </g:if>
                <g:else>
                    <a class="btn-text" href="${createLink(controller: 'account', action: 'enable', id: account.userId, params: [origin: request.forwardURI.toString().decodeURL()])}">Enable</a>
                </g:else>
                <a class="btn-text" href="${createLink(controller: 'account', action: 'delete', id: account?.userId)}" onclick="return confirm('Are you sure?');">Delete</a>
            </g:unless>
        </sec:ifAllGranted>
    </div>
    <br/>

    <table style="border: none;">
        <tr>
            <td width="15%"><h2>Email Address:</h2></td>
            <td>
                <g:formRemote onSuccess="jQuery('#${account?.userId}_emailAddress').effect('highlight',{color: '#90ee90'},1000);" onFailure="jQuery('#${account?.userId}_emailAddress').effect('highlight',{color: 'red'},1000);" name="f1" url="[controller: 'account', action: 'updateField', id: account?.userId]">
                    <g:hiddenField name="field" value="emailAddress"/>
                    <input id="${account?.userId}_emailAddress" class="ui-corner-all" type="text" name="value" value="${account?.emailAddress}" style="width: 50%;"/>
                    <a href="javascript: void();" onclick="jQuery('#f1').submit();" name="submit" class="btn save" icon="ui-icon-disk"></a>
                </g:formRemote>
            </td>
        </tr>

        <tr>
            <td width="15%"><h2>First Name:</h2></td>
            <td>
                <g:formRemote onSuccess="jQuery('#${account?.userId}_firstName').effect('highlight',{color: '#90ee90'},1000);" onFailure="jQuery('#${account?.userId}_firstName').effect('highlight',{color: 'red'},1000);" name="ffirstName" url="[controller: 'account', action: 'updateField', id: account?.userId]">
                    <g:hiddenField name="field" value="firstName"/>
                    <input id="${account?.userId}_firstName" class="ui-corner-all" type="text" name="value" value="${account?.firstName}" style="width: 50%;"/>
                    <a href="javascript: void();" onclick="jQuery('#ffirstName').submit();" name="submit" class="btn save" icon="ui-icon-disk"></a>
                </g:formRemote>
            </td>
        </tr>

        <tr>
            <td width="15%"><h2>Last Name:</h2></td>
            <td>
                <g:formRemote onSuccess="jQuery('#${account?.userId}_lastName').effect('highlight',{color: '#90ee90'},1000);" onFailure="jQuery('#${account?.userId}_lastName').effect('highlight',{color: 'red'},1000);" name="flastName" url="[controller: 'account', action: 'updateField', id: account?.userId]">
                    <g:hiddenField name="field" value="lastName"/>
                    <input id="${account?.userId}_lastName" class="ui-corner-all" type="text" name="value" value="${account?.lastName}" style="width: 50%;"/>
                    <a href="javascript: void();" onclick="jQuery('#flastName').submit();" name="submit" class="btn save" icon="ui-icon-disk"></a>
                </g:formRemote>
            </td>
        </tr>
    %{--<tr>
        <td><h2>Change Password:</h2></td>
        <td>
            <g:formRemote onSuccess="jQuery('#${account?.userId}_password2').effect('highlight',{color: '#90ee90'},1000);" onFailure="jQuery('#${account?.userId}_password2').effect('highlight',{color: 'red'},1000);" name="fchangepassword" url="[controller: 'account', action: 'updateField', id: account?.userId]">
                <g:hiddenField name="field" value="password"/>
                <table style="width: 50%;">
                    --}%%{--<tr>
                        <td width="15%">Current Password:</td>
                        <td>
                            <input id="${account?.userId}_oldPassword" class="ui-corner-all" type="password" name="oldPassword" style="width: 50%;"/>
                        </td>
                    </tr>--}%%{--
                    <tr>
                        <td width="15%">New Password:</td>
                        <td>
                            <input id="${account?.userId}_newPassword1" class="ui-corner-all" type="password" name="newPassword1" style="width: 50%;"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="15%">Confirm Password:</td>
                        <td>
                            <input id="${account?.userId}_newPassword2" class="ui-corner-all" type="password" name="newPassword2" style="width: 50%;"/>
                            <a href="javascript: void();" onclick="jQuery('#fchangepassword').submit();" name="submit" class="btn-text" icon="ui-icon-disk">Change</a>
                        </td>
                    </tr>
                </table>
            </g:formRemote>
        </td>
    </tr>--}%
        <g:unless test="${account.username.equals('admin')}">
            <g:unless test="${account.userId.equals(sec.loggedInUserInfo(field: 'userId').toString())}">
                <tr>
                    <td><h2>Roles:</h2></td>
                    <td>
                        <g:formRemote onSuccess="jQuery('#rolesTable').effect('highlight',{color: '#90ee90'},1000);" onFailure="jQuery('#rolesTable').effect('highlight',{color: 'red'},1000);" name="roles_form" url="[controller: 'account', action: 'updateRole', id: account?.userId]">
                            <table id="rolesTable">
                                <tr>
                                    <td colspan="1">

                                        <input onchange="jQuery('#roles_form').submit();" type="checkbox" name="c1" id="${Roles.ROLE_ADMIN}" ${roles.get(Roles.ROLE_ADMIN)} value="${Roles.ROLE_ADMIN}" /> <label id="${Roles.ROLE_ADMIN}_label" for="${Roles.ROLE_ADMIN}">Admin</label>

                                    </td>
                                    <td colspan="1">
                                        <input onchange="jQuery('#roles_form').submit();" type="checkbox" name="c1" id="${Roles.ROLE_SCRIPT_ADMIN}" ${roles.get(Roles.ROLE_SCRIPT_ADMIN)} value="${Roles.ROLE_SCRIPT_ADMIN}" /> <label for="${Roles.ROLE_SCRIPT_ADMIN}">Manage Scripts</label>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="1">
                                        <input onchange="jQuery('#roles_form').submit();" type="checkbox" name="c1" id="${Roles.ROLE_JOB_ADMIN}" ${roles.get(Roles.ROLE_JOB_ADMIN)} value="${Roles.ROLE_JOB_ADMIN}" /> <label for="${Roles.ROLE_JOB_ADMIN}">Manage Jobs</label>
                                    </td>
                                    <td colspan="1">
                                        <input onchange="jQuery('#roles_form').submit();" type="checkbox" name="c1" id="${Roles.ROLE_JOB_RUN}" ${roles.get(Roles.ROLE_JOB_RUN)} value="${Roles.ROLE_JOB_RUN}" /> <label for="${Roles.ROLE_JOB_RUN}">Run Jobs</label>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="1">
                                        <input onchange="jQuery('#roles_form').submit();" type="checkbox" name="c1" id="${Roles.ROLE_RESULTS_ADMIN}" ${roles.get(Roles.ROLE_RESULTS_ADMIN)} value="${Roles.ROLE_RESULTS_ADMIN}" /> <label for="${Roles.ROLE_RESULTS_ADMIN}">Manage Results</label>
                                    </td>
                                    <td colspan="1">
                                        <input onchange="jQuery('#roles_form').submit();" type="checkbox" name="c1" id="${Roles.ROLE_RESULTS_VIEW}" ${roles.get(Roles.ROLE_RESULTS_VIEW)} value="${Roles.ROLE_RESULTS_VIEW}" /> <label for="${Roles.ROLE_RESULTS_VIEW}">View Results</label>
                                    </td>
                                </tr>
                            </table>
                        </g:formRemote>
                    </td>
                </tr>

                <tr>
                    <td colspan="2">
                        <h2>Allowed Scripts and Jobs:</h2>
                        <g:formRemote onSuccess="jQuery('#scriptsAndJobsTable').effect('highlight',{color: '#90ee90'},1000);" onFailure="jQuery('#scriptsAndJobsTable').effect('highlight',{color: 'red'},1000);" name="scriptsAndJobs_form" url="[controller: 'account', action: 'updateScriptsAndJobs', id: account?.userId]">
                            <table id="scriptsAndJobsTable">
                                <g:each in="${AntScript.findAll().sort{ it.description}}" status="scriptIndex" var="script">
                                    <tr class="${scriptIndex%2 ? 'odd' : 'even'}">
                                        <td>
                                            <h2><input ${AntScriptUser.countByUserAndScript(account,script)==0 ?: 'checked' } onchange="jQuery('#scriptsAndJobs_form').submit();" type="checkbox" name="scripts" id="${script.scriptId}" value="${script.scriptId}" /> ${script.description}</h2>

                                            <table>
                                                <g:each in="${AntJob.findAllByScript(script).sort{ it.name}}" status="jobIndex" var="job">
                                                    <tr class="${jobIndex%2 ? 'odd' : 'even'}">
                                                        <td style="width: 1%;">
                                                            <input ${AntJobUser.countByUserAndJob(account,job)==0 ?: 'checked' }  onchange="jQuery('#scriptsAndJobs_form').submit();" type="checkbox" name="jobs" id="${job.jobId}" value="${job.jobId}" />
                                                        </td>
                                                        <td>${job.name}</td>
                                                    </tr>
                                                </g:each>
                                            </table>

                                        </td>
                                    </tr>
                                </g:each>
                            </table>
                        </g:formRemote>
                    </td>
                </tr>
            </g:unless>
        </g:unless>

    </table>

</div>

</body>
</html>